#include"Command.hpp"
#include "TcpServer.hpp"
// #include "Dict.hpp"

std::string defaulthandler(const std::string &word, InetAddr &addr)
{
    LOG(LogLevel::DEBUG) << "回调到了defaulthandler";
    std::string s = "haha, ";
    s += word;
    return s;
}


void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " port" << std::endl;
}

// 远程命令执行的功能！
// ./tcpserver port
int main(int argc,char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);

    Enable_Console_Log_Strategy();

    //1.命令执行模块
    Command cmd;

    //2.网络服务器对象，通信功能
    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port,[&cmd](const std::string &command,InetAddr &addr)
    {
        return cmd.Execute(command,addr);
    });
    tsvr->Init();
    tsvr->Run();
    return 0;
}